@extends('admin.layout.common')
@section('content')
    <link rel="stylesheet" type="text/css" href="{{URL::asset('css/app.css')}}">
    <link rel="stylesheet" type="text/css" href="{{URL::asset('css/user/AddEmployees.css')}}">
    <style>
        .error{
            color:red;
        }
    </style>
    <div class="content">
        <h1 class="h1">添加员工</h1>
        <form method="post" class="cmxform" id="addForm" action="{{url('/admin/addManager')}}">
            {{csrf_field()}}
            <input type="hidden"/>
            <p><label for="work_number">坐席工号：<input id="work_number" type="text" name="work_number"></label></p>
            <p>
                <label for="real_name">职工姓名：<input id="real_name" type="text" name="real_name"></label>
                <label for="phone">联系电话：<input id="phone" type="text" name="phone" number></label>
                <label for="email">工作邮箱：<input type="email" name="email"></label><br/>
            </p>
            <p>
                <label for="department"><span class="red_icon">*</span>所在部门：
                    <select name="department" style=""  id="department">
                        <option value="">--请选择--</option>
                        @foreach($list as $value)
                            <option value="{{$value['id']}}">{{$value['name_cn']}}</option>
                        @endforeach
                    </select>
                </label>
                <label for="role_ids"><span class="red_icon">*</span>角色职务：
                    <select name="role_ids" style="" id="role">
                        <option value="">--请选择--</option>
                    </select>
                </label>
                {{--<label for="work_name">岗位名称：--}}
                    {{--<input id="work_name" type="text" name="work_name">--}}
                {{--</label>--}}
                <label for="name"><span class="red_icon">*</span>登录名：&nbsp;&nbsp;<input type="text" name="name"></label><br/>
            </p>
           {{--<p>--}}
               {{--<label for="name"><span class="red_icon">*</span>登录名：&nbsp;&nbsp;<input type="text" name="name"></label>--}}
           {{--</p>--}}

            <p><input class="submit" type="submit" name="" value="确定信息"></p>
        </form>
    </div>

<script type="text/javascript" src="{{URL::asset('js/user/AddEmployees.js')}}"></script>
<script>
    $('#department').change(function(){
        var data = $("#department").val();     
        $.ajax({
            type: "POST",
            url: "http://{{$_SERVER['HTTP_HOST']}}/admin/findRole",
            data:{department_id:data},
            dataType: "json",
            success: function(data){
                $("#role").find("option").remove(); 
                for(var a in data){
                    var role = data[a].name_cn;
                    var role_id = data[a].id;
                    $("#role").append('<option value="'+role_id+'">'+role+'</option>');
                }
            }
        })
    });

    $().ready(function() {
        $("#addForm").validate({
            rules: {
                // work_number: {
                //     required: true,
                //     number: true,
                // },
                real_name: {
                    required: true,
                    minlength: 2,
                },
                department: {
                    required: true,
                },
                phone: {
                    required: true,
                    maxlength: 11,
                    number: true
                },
                email: {
                    required: true,
                    email: true
                },
                role_ids: {
                    required: true,
                },
                work_name: {
                    required: true,
                    minlength: 2,
                },
                name: {
                    required: true,
                    minlength: 2,
                }




            },
            messages: {
                // work_number: {
                //     required: "请输入正确坐席工号",
                //     number: "请输入有效的数字",
                // },
                real_name: {
                    required: "请输入职工姓名",
                    minlength: "职工姓名最少由两个字符组成",
                },
                phone: {
                    number:"",
                    required: "请输入联系电话",
                    maxlength: "请正确填写电话号码",
                    number:''
                },
                email: "请输入一个正确的邮箱",
                role_ids: {
                    required: "请选择角色职务"
                },
                department: {
                    required: "请选择部门"
                },
                work_name: {
                    required: "请输入岗位名称",
                    minlength: "岗位名称最少由两个字符组成",
                },
                name: {
                    required: "请输入登录名",
                    minlength: "登录名最少由两个字符组成",
                }
            }
        })
    });

</script>
@endsection